import com.genexus.*;
import com.genexus.xml.*;

public final class GxObjectCollection extends GXObjectCollectionBase
{
   public GxObjectCollection( Class elementsType ,
                              String elementsName ,
                              String containedXmlNamespace )
   {
      super(elementsType, elementsName, containedXmlNamespace);
   }

   public GxObjectCollection( )
   {
   }

   public short readxml( com.genexus.xml.XMLReader oReader )
   {
      short currError ;
      String arrayType ;
      short gxi ;
      currError = (short)(1) ;
      arrayType = "" ;
      gxi = 0 ;
      while ( ( gxi <= oReader.getAttributeCount() ) )
      {
         if ( ( GXutil.strcmp(oReader.getAttributeLocalName(gxi), "arrayType") == 0 ) )
         {
            arrayType = oReader.getAttributeByIndex(gxi) ;
         }
         gxi = (short)(gxi+1) ;
      }
      if ( ( GXutil.strcmp(arrayType, "") != 0 ) )
      {
         currError = readEncodedArray(arrayType,oReader) ;
      }
      else
      {
         currError = readCollection(oReader) ;
      }
      return currError ;
   }

   public short readEncodedArray( String arrayType ,
                                  com.genexus.xml.XMLReader oReader )
   {
      short currError ;
      int arrayLength ;
      int arraySizeStartPos ;
      int arraySizeLength ;
      short gxi ;
      arraySizeStartPos = (int)(GXutil.strSearch( arrayType, "[", (short)(1))+1) ;
      arraySizeLength = (int)(GXutil.len( arrayType)-arraySizeStartPos) ;
      if ( ( arraySizeStartPos == 1 ) || ( arraySizeLength == 0 ) )
      {
         throw new RuntimeException("GxObjectCollectionBase error: Could not read encoded array size" + "(" + 0+ ")");
      }
      arrayLength = (int)(GXutil.val( GXutil.substring( arrayType, arraySizeStartPos, arraySizeLength))) ;
      currError = (short)(1) ;
      oReader.read();
      gxi = 0 ;
      while ( ( gxi < arrayLength ) && ( currError > 0 ) )
      {
         currError = AddObjectInstance(oReader) ;
         oReader.read();
         gxi = (short)(gxi+1) ;
      }
      return currError ;
   }

   public short readCollection( com.genexus.xml.XMLReader oReader )
   {
      short currError ;
      String sTagName ;
      currError = (short)(1) ;
      oReader.read();
      sTagName = oReader.getName() ;
      this.Clear();
      while ( ( GXutil.strcmp(oReader.getName(), sTagName) == 0 ) && ( oReader.getNodeType() == 1 ) && ( currError > 0 ) )
      {
         currError = AddObjectInstance(oReader) ;
         oReader.read();
      }
      return currError ;
   }

}

